package com.cgc.venus.server.core.k8s.impl;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "k8s")
public class K8sConfig {
    private String masterURL;
    private String clientCertData;
    private String clientKeyData;
    private String caCertData;

    @Bean
    public KubernetesClient k8sClient(){
        Config config=new ConfigBuilder()
                .withMasterUrl(masterURL)
                .withClientCertData(clientCertData)
                .withClientKeyData(clientKeyData)
                .withCaCertData(caCertData)
                .build();
        KubernetesClient kubernetesClient=new DefaultKubernetesClient(config);
        return kubernetesClient;
    }

    public String getMasterURL() {
        return masterURL;
    }
    public void setMasterURL(String masterURL) {
        this.masterURL = masterURL;
    }

    public String getClientCertData() {
        return clientCertData;
    }

    public void setClientCertData(String clientCertData) {
        this.clientCertData = clientCertData;
    }

    public String getClientKeyData() {
        return clientKeyData;
    }

    public void setClientKeyData(String clientKeyData) {
        this.clientKeyData = clientKeyData;
    }

    public String getCaCertData() {
        return caCertData;
    }

    public void setCaCertData(String caCertData) {
        this.caCertData = caCertData;
    }
}
